/*
 * This file is part of GuitarMaster.
 * 
 * GuitarMaster is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GuitarMaster is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with GuitarMaster.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.paris5.master2.guitarmaster.bean;

/*
 * $Id: EcomDaoService.java 7 2013-03-13 08:38:30Z nedjahi.mourad@gmail.com $
 * 
 * $HeadURL: https://com-paris5-master2-guitarmaster-ejb.googlecode.com/svn/trunk/com.paris5.master2.guitarmaster-ejb/src/java/com/paris5/master2/guitarmaster/dao/EcomDaoService.java $
 * $Revision: 7 $
 * $Date: 2013-03-13 09:38:30 +0100 (mer., 13 mars 2013) $
 * $Author: nedjahi.mourad@gmail.com $
 */
public class EcomScore implements EcomBean {
    
    private Integer id;
    private int voteCount;
    private int voteValue;
    private int score;

    public EcomScore() {
        this.score = this.voteCount = this.voteValue = 0;
    }

    public EcomScore(Integer id, int voteCount, int voteValue) {
        this.id = id;
        this.voteCount = voteCount > 0? voteCount: 0;
        this.voteValue = voteValue > 0? voteValue : 0;
        calculateScore();
    }

    public Integer getId() {
        return id;
    }

    public int getVoteCount() {
        return voteCount;
    }

    public int getScore() {
        return score;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void setVoteCount(int voteCount) {
        this.voteCount = voteCount;
        calculateScore();
    }

    public int getVoteValue() {
        return voteValue;
    }

    public void setVoteValue(int value) {
        this.voteValue = value > 0? value : 0;
        calculateScore();
    }

    @Override
    public int hashCode() {
        int hash = 3;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final EcomScore other = (EcomScore) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.voteCount != other.voteCount) {
            return false;
        }
        if (this.voteValue != other.voteValue) {
            return false;
        }
        if (this.score != other.score) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "EcomScore{" + "id=" + id + ", voteCount=" + voteCount + ", voteValue=" + voteValue + ", score=" + score + '}';
    }

    private void calculateScore() {
        if(this.voteCount==0){
            this.score = this.voteCount = this.voteValue = 0;
        }
        else {
            this.score = (this.voteValue *100) / this.voteCount;
        }
    }
}
